package com.hqyj.controller;

import com.hqyj.pojo.Log;
import com.hqyj.pojo.PageData;
import com.hqyj.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/log")
public class LogController {

    @Autowired
    private LogService logService;

    @RequestMapping("/getLogAll2")
    public String getAllUserByPage(Integer pageNumber, Integer pageSize, ModelMap modelMap){
        if(pageNumber == null){
            pageNumber = 1;
        }
        pageSize = 5;

        //调用服务层换回模型数据
        PageData<Log> logByPage = logService.getLogByPage(pageNumber, pageSize);
        //给视图传递上下文参数
        modelMap.put("pageData", logByPage);
        return "log/log2";
    }

    @RequestMapping("/addLog")
    @ResponseBody
    public Map<String, Object> addLog(Integer userId, String modelName, String operate){
        Map<String, Object> result = new HashMap<>();

        int i = logService.insertLog(userId,modelName,operate);

        result.put("code",1);
        result.put("massage","success");
        result.put("addLog",i);
        return result;
    }

    @RequestMapping("/getLogAll")
    public String  getLogByLike(Integer PageNumber, Integer PageSize, ModelMap modelMap, String id){
        if(PageNumber == null){
            PageNumber = 1;
        }
        PageSize = 5;
        if(id == null){
            id = "";
        }

        //调用服务层换回模型数据
        PageData<Log> logByLike = logService.getLogByLike(PageNumber, PageSize, id);
        //给视图传递上下文参数
        modelMap.put("pageLike", logByLike);

        return "log/log";
    }

}
